package monitor.rest;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import monitor.model.dao.HistoryDAO;
import monitor.model.parameter.TimePoint;

@Path("android")
public class AndroidServices {
	private final static int HTTP_OK = 200;
	private final static int HTTP_INTERNAL_ERROR = 500;
	
	/**
	 * This REST service consumes ECU data, sent by mobile device.
	 * 
	 * @param carId Car identifier
	 * @param timePoints List of obtained parameters, location and creation date.
	 * @return HTTP response 200 for success or HTTP 500 if error occurred.
	 */
	@POST
	@Path("history-update/{carId}")
	@Consumes(MediaType.APPLICATION_JSON)
	public Response updateCarHistory(@PathParam("carId") String carId, List<TimePoint> timePoints) {
		try {
			HistoryDAO.getInstance().insertEcuData(carId, timePoints);
			return Response.status(HTTP_OK).build();
		} catch (Exception e) {
			return Response.status(HTTP_INTERNAL_ERROR).build();
		}
	}
}
